/**

This file is part of MaCI/GIMnet.

MaCI/GIMnet is free software: you can redistribute it and/or modify it 
under the terms of the GNU Lesser General Public License as published 
by the Free Software Foundation, either version 3 of the License, or 
(at your option) any later version.

MaCI/GIMnet is distributed in the hope that it will be useful, but WITHOUT 
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public 
License for more details.

You should have received a copy of the GNU Lesser General Public 
License along with GIMnet. (See COPYING.LESSER) If not, see 
<http://www.gnu.org/licenses/>.

**/
#ifndef ___MAPDISPLAY_HPP
#define ___MAPDISPLAY_HPP

#define GIMI_CLIENT_API (20000)
#include "gimi.h"
#include "MapClient.hpp"
#include "Mapper.hpp"

#include <GL/gl.h>

enum EMapDetailLevel
{
  KHighDetail = 1,
  KLowDetail  = 2
};

class CMapDisplay : public MaCI::Map::CMapClientCallback
{
  public:
    CMapDisplay();
    
    ~CMapDisplay();
    
    void Draw();
    
    void UpdateWholeMap(MaCI::Map::CMapData &mapData);
    
    void DisplayHeightMap(bool display) {showHeightMap=display;}
    
    void DisplayOccupancyGrid(bool display) {showOccu=display;}
    
    void DisplayLineMap(bool display) {showLines=display;}
    
    void DisplayAreas(bool display) {showAreas=display;}
    
    bool IsHeightMapDisplayed() {return showHeightMap;}
    
    bool IsOccupancyGridDisplayed() {return showOccu;}
    
    bool IsLineMapDisplayed() {return showLines;}
    
    bool IsAreasDisplayed() {return showAreas;}
    
    void SetZ(float z) {this->z=z;}
    
    float GetZ() {return z;}
    
    bool SetDetailLevel(EMapDetailLevel level);
    
    EMapDetailLevel GetDetailLevel() {return detailLevel;}
    
    void SetOccupancyThreshold(float threshold);
    
    float SetOccupancyThreshold(){ return occuThreshold; }
    
    //callback for map client
    void OnMapDataEvent(const MaCI::Map::CMapData &aData, 
                          const unsigned int aDataSequence, 
                          MaCI::Map::CMapClient &aMapClient);
    
  private:
    struct blockData //user data for mapper blocks
    {
      blockData()
        :highDetailList(0),lowDetailList(0){}
      
      GLuint highDetailList; //high detail list, shown on close zoom
      GLuint lowDetailList;  //low detail list
    };
    
    CMapper mapper;
    gmbVector updatedGroundBlocks;
    occuVector updatedOccuBlocks;
    ownMutexHandle mapperMutex;
    MaCI::Map::CMapClient *mapClient;
    
    bool showHeightMap;
    bool showOccu;
    bool showLines;
    bool showAreas;
    
    float z;
    
    int y_orientation;
    
    float occuThreshold;
    
    EMapDetailLevel detailLevel;
    
    void createHeightMapDisplayList(const TGroundModelBlock* block);

    void createOccuDisplayList(const TOccuBlock* block);
    
    void drawHeightMapBlock(int samplesPerQuad, const TGroundModelBlock* block);
    
    void drawOccuBlock(int samplesPerQuad, const TOccuBlock* block);
    
    bool isDrawn(const TGroundModelBlock* block);
    
    bool isDrawn(const TOccuBlock* block);

    void displayHeightMapBlock(const TGroundModelBlock* block);
    
    void displayOccuBlock(const TOccuBlock* block);
    
    void displayBlock(blockData* bd);
};


#endif //___MAPDISPLAY_HPP
